package com.googlecode.spreadit.util;

import java.util.LinkedList;
import java.util.List;

import android.content.Context;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

/**
 * Since the {@link ListView} is cumbersome to some extend this utility class
 * aims at simplifying the creation and handling of {@link ListView} content.
 * 
 * @author Markus L. Dechert (markus.dechert@googlemail.com)
 */
public class ListViewUtil {

	public static ListAdapter createListAdapterByResourceStrings(
			Context context, int[] resIdEntryStrings) {

		if ((context == null) || (resIdEntryStrings == null)) {
			throw new IllegalArgumentException("context: " + context
					+ ", resIdEntryStrings:" + resIdEntryStrings);
		}

		List<String> sList = new LinkedList<String>();
		for (int resId : resIdEntryStrings) {
			String entry = context.getString(resId);
			sList.add(entry);
		}

		ListAdapter la = new ArrayAdapter<String>(context,
				android.R.layout.simple_list_item_1,
				sList.toArray(new String[] {}));

		return la;

	}
}
